package model;

import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.read.listener.ReadListener;

import java.util.LinkedList;

/**
 * @author 刀氏春秋
 * @date 2023/5/15
 */
public class ReadExcelUtil<DTO> {
    public LinkedList<DTO> readRawDataFromExcel(String fileName, Class<DTO> clz) {
        LinkedList<DTO> rawData = new LinkedList<>();
        EasyExcel.read(fileName, clz, new ReadListener<DTO>() {
            @Override
            public void invoke(DTO dataItem, AnalysisContext analysisContext) {
                rawData.add(dataItem);
            }

            @Override
            public void doAfterAllAnalysed(AnalysisContext analysisContext) {
                System.out.printf("file reading completed, %d recordings.%n",rawData.size());
            }
        }).sheet().doRead();

        return rawData;
    }
}
